<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h2 {
            text-align: center;
        }

        table {
            border: 1px solid rgb(244, 213, 213);
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
        }

        tr,
        td,
        th {
            border: 1px solid rgb(213, 202, 202);
            padding: 10px 20px;
        }

        tr:first-child {
            background-color: #dcd4d4;
        }

        table tr:not(:first-child):hover {
            background-color: #f3eded;
        }
    </style>
</head>

<body>
    <h2>学生列表</h2>
    <table>
        <tr>
            <th>序号</th>
            <th>性别</th>
            <th>年龄</th>
            <th>性别</th>
            <th>家乡</th>
        </tr>
        <script>
            let students = [
                { name: '小明', age: 14, gender: '男', hometown: '河北省' },
                { name: '小米', age: 15, gender: '女', hometown: '河北省' },
                { name: '小李', age: 14, gender: '男', hometown: '河北省' },
                { name: '小红', age: 18, gender: '女', hometown: '河北省' },
                { name: '小红', age: 18, gender: '女', hometown: '河北省' }
            ]
            for (let i = 0; i < students.length; i++) {
                document.write(`
                    <tr>
                        <td>${i + 1}</td>
                        <td>${students[i].name}</td>
                        <td>${students[i].age}</td>
                        <td>${students[i].gender}</td>
                        <td>${students[i].hometown}</td>
                    </tr>
                `)
            }

            //         <tr>     中间的写法错误
            //             <td>${students[i][k]}</td>
            //             <td>${students[i][k]}</td>
            //             <td>${students[i][k]}</td>
            //             <td>${students[i][k]}</td>
            //             <td>${students[i][k]}</td>
            //         </tr>
        </script>

    </table>

</body>

</html>